---@class UIExpeditionHeroList : UIBase
UIExpeditionHeroList = UIBase.New(PanelResNames.UIExpeditionHeroList)
local t = UIExpeditionHeroList

function t.Init(type)
    t.type = type or 1;
    UIBase.Init(t)
end

function t:OnCreate()
    self.btnClose = self:GetChild("CloseBg")
    self.itemList = self:GetList("HeroList")

    self:SetDynamicList(self.itemList,self.ItemRender)
    self:RegisterOnClick(self.btnClose,self.ClickClose)
end

function t:OnEnable()
    if self.type == 1 then
        logicMgr.ExpeditionMgr.SetHeroDeadFlag()
    elseif self.type == 2 then
        logicMgr.LongJourneyHellManager.SetHeroDeadFlag()
    end
    self:Refresh()
end
function t:OnDisable()
    if self.type == 1 then
        logicMgr.ExpeditionMgr.ClearHeroDeadFlag()
    elseif self.type == 2 then
        logicMgr.LongJourneyHellManager.ClearHeroDeadFlag()
    end
end
function t:OnDestroy()
end
function t:Refresh()
    self.heroInfoList = logicMgr.HeroManager.getOwnerHeroList()
    table.sort(self.heroInfoList,logicMgr.HeroManager.sortHero)
    self.itemList.numItems = #self.heroInfoList
end
function t:ItemRender(index,go)
    local data = self.heroInfoList[index]
    local item = logicMgr.CtrlManager.GetCtrl(PanelNames.HeadRectItem)
    item.initData(go,data)
    local hp = 100;
    local energy = 100;
    if self.type == 1 then
        local info = logicMgr.ExpeditionMgr.GetHeroInfo(data.partnerId)
        if info then
            hp = info.hp;
            energy = info.energy;
        end
    elseif self.type == 2 then
        local info = logicMgr.LongJourneyHellManager.getMemberList(data.partnerId);
        if info then
            hp = info.hpRate;
            energy = info.mpRate;
        end
    end
    item.UpdateHPMPBar(go,hp,energy);
end

function t:ClickClose()
    closeUI(PanelResNames.UIExpeditionHeroList)
end
return t